package ljl.alg.jianzhioffer.round3.medium;

import java.util.LinkedList;

public class _59_MaxQueue {


    LinkedList<Integer> data = new LinkedList<>();
    LinkedList<Integer> max = new LinkedList<>();
    public int max_value() {
        return max.size() == 0 ? -1 : max.peek();
    }

    public void push_back(int value) {
        data.offer(value);
        while (max.size() > 0 && max.peekLast() < value)
            max.pollLast();
        max.offer(value);
    }

    public int pop_front() {
        if (data.size() == 0)
            return -1;
        if (max.peek().intValue() == data.peek())
            max.poll();
        return data.size() == 0 ? -1 : data.poll();
    }
}
